<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<!-- MAIN ELEMENT -->
	<xs:element name="BusinessRules" type="BusinessRulesType"/>
	<!-- COMPLEX TYPES -->
	<xs:complexType name="CompareType">
		<xs:sequence>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Rule" type="RuleType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attributeGroup ref="CompareAttributes"/>
	</xs:complexType>
	<xs:complexType name="ConditionType">
		<xs:sequence minOccurs="0" maxOccurs="unbounded">
			<xs:element name="Compare" type="CompareType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Condition" type="ConditionType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attributeGroup ref="ConditionTypeAttributes"/>
	</xs:complexType>
	<xs:complexType name="IfType">
		<xs:sequence>
			<xs:element name="Condition" type="ConditionType" maxOccurs="unbounded"/>
			<xs:element name="Do" type="NxBREType"/>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="ForEachType">
		<xs:complexContent>
			<xs:extension base="NxBREType">
				<xs:attributeGroup ref="ForEachAttributes"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="LogicType">
		<xs:sequence>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="If" type="IfType"/>
			<xs:element name="ElseIf" type="IfType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Else" type="NxBREType" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="LogType">
		<xs:attributeGroup ref="LogAttributes"/>
	</xs:complexType>
	<xs:complexType name="RetractType">
		<xs:attributeGroup ref="IdRequired"/>
	</xs:complexType>
	<xs:complexType name="ParameterType">
		<xs:attributeGroup ref="ParameterAttributes"/>
	</xs:complexType>
	<xs:complexType name="RuleType">
		<xs:sequence>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Parameter" type="ParameterType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attributeGroup ref="RuleAttributes"/>
	</xs:complexType>
	<xs:complexType name="SetType">
		<xs:complexContent>
			<xs:extension base="NxBREType">
				<xs:attributeGroup ref="IdRequired"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="InvokeSetType">
		<xs:attributeGroup ref="InvokeSetAttributes"/>
	</xs:complexType>
	<xs:group name="NxBREGroup">
		<xs:sequence>
			<xs:element name="Rule" type="RuleType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Log" type="LogType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Logic" type="LogicType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="While" type="IfType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="InvokeSet" type="InvokeSetType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="ForEach" type="ForEachType" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="Retract" type="RetractType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:group>
	<xs:complexType name="NxBREType">
		<xs:sequence minOccurs="0" maxOccurs="unbounded">
			<xs:group ref="NxBREGroup"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="BusinessRulesType">
		<xs:sequence minOccurs="0" maxOccurs="unbounded">
			<xs:group ref="NxBREGroup"/>
			<xs:element name="Set" type="SetType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<!-- ATTRIBUTE GROUPS -->
	<xs:attributeGroup name="ForEachAttributes">
		<xs:attribute name="id" type="xs:string"/>
		<xs:attribute name="ruleValue" type="xs:string"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="ConditionTypeAttributes">
		<xs:attribute name="type" type="ConditionTypeList"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="CompareAttributes">
		<xs:attribute name="operator" type="xs:string" use="required"/>
		<xs:attribute name="leftId" type="xs:string" use="required"/>
		<xs:attribute name="rightId" type="xs:string" use="required"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="LogAttributes">
		<xs:attribute name="level" type="xs:integer" use="required"/>
		<xs:attribute name="msg" type="xs:string"/>
		<xs:attribute name="msgId" type="xs:string"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="ParameterAttributes">
		<xs:attribute name="name" type="xs:string" use="required"/>
		<xs:attribute name="value" type="xs:string"/>
		<xs:attribute name="type" type="xs:string"/>
		<xs:attribute name="ruleValue" type="xs:string"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="RuleAttributes">
		<xs:attribute name="factory" type="xs:string"/>
		<xs:attribute name="id" type="xs:string" use="required"/>
		<xs:attribute name="step" type="xs:string"/>
		<!-- Factory is not required because I want to add support for -->
		<!-- developers to pass in a BRERuleContext with factories already -->
		<!-- In them.  This way they can have more stateful objects -->
	</xs:attributeGroup>
	<xs:attributeGroup name="IdRequired">
		<xs:attribute name="id" type="xs:string" use="required"/>
	</xs:attributeGroup>
	<xs:attributeGroup name="InvokeSetAttributes">
		<xs:attribute name="id" type="xs:string"/>
		<xs:attribute name="ruleValue" type="xs:string"/>
	</xs:attributeGroup>
	<!-- SIMPLE TYPES -->
	<xs:simpleType name="ConditionTypeList">
		<xs:restriction base="xs:NMTOKEN">
			<xs:enumeration value="AND"/>
			<xs:enumeration value="OR"/>
			<xs:enumeration value="NOT"/>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>
